package com.chixing.ih.module.task.service.impl;

import com.chixing.ih.module.programmer.mapper.ProgrammerMapper;
import com.chixing.ih.module.task.mapper.OrderMapper;
import com.chixing.ih.module.task.mapper.ProgressTaskMapper;
import com.chixing.ih.module.task.pojo.DTO.ProgressTaskDTO;
import com.chixing.ih.module.task.pojo.Order;
import com.chixing.ih.module.task.pojo.ProgressTask;
import com.chixing.ih.module.task.service.IProgressTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 目的:
 *
 * @author ：zcw
 * @version: 1.0  2020/10/3 17:23
 */
@Service
@Transactional
public class ProgressTaskServiceImpl implements IProgressTaskService {

    @Autowired
    private ProgressTaskMapper progressTaskMapper;

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private ProgrammerMapper programmerMapper;


    @Override
    public List<ProgressTaskDTO> findAll(Long taskId) {
        Order order = orderMapper.findOne(taskId);
        if (null != order) {
            List<ProgressTaskDTO> list = progressTaskMapper.findAll(order.getOrderId());
            for (int i = 0; i < list.size(); i++) {
                list.get(i).setNickName(programmerMapper.getOne(order.getReceiveTaskUserId()).getNickName());
            }
            return list;
        }
        return null;
    }

    @Override
    public ProgressTask findOne(Long progressTaskId) {
        ProgressTask progressTask = progressTaskMapper.findOne(progressTaskId);
        return progressTask;
    }

    @Override
    public int insertOne(ProgressTaskDTO progressTask) {

        Order order = orderMapper.findOne(progressTask.getTaskId());

        ProgressTask task = new ProgressTask();
        task.setOrderId(order.getOrderId());
        task.setSubTask(progressTask.getSubTask());
        task.setCreateTime(new Date());
        return progressTaskMapper.insertOne(task);
    }
}
